<!--
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-06-02 11:30:50
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-06-02 11:46:11
 * @FilePath: \code\code\JavaScript\ES6-\31-构造函数继承.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE   
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //手机
        function Phone(brand, price) {
            this.brand = brand;
            this.price = price;
        }
        //在原型上添加call方法
        Phone.prototype.call = () => {
            console.log('我可以打电话');
        };

        //智能手机
        function SmartPhone(brand, price, color, size) {
            //利用call方法改变this指向
            Phone.call(this, brand, price);
            this.color = color;
            this.size = size;
        }
        //设置子级构造函数的原型
        SmartPhone.prototype = new Phone();
        // 矫正
        SmartPhone.prototype.constructor = SmartPhone;


        //声明子类方法
        SmartPhone.prototype.photo = () => {
            console.log('拍照功能');
        };
        SmartPhone.prototype.playGame = () => {
            console.log('玩游戏');
        }

        // 实例化一个对象
        const chuizi = new SmartPhone('锤子', 1999, '黑色', '123');
        console.log(chuizi);
        chuizi.photo();
        chuizi.call();
    </script>
</body>

</html>